<?php

	/*
	 * installer changelog:
	 * 
	 * 0.3 - added information check and theme creation
	 * 0.2 - login credentials set possibilitys 
	 * 0.1 - first stable installer
	 */

	define('YMT', true);
	define('BACK_TRACE', '../');
	
	ini_set('display_errors', 1); error_reporting(E_ALL);

	session_start();
	
	/* requires */
	
	require_once '../Yomm/Config.class.php';
	
	$_step = 1;
	
	$_installer = "0.3"; // installer version
	
	if(isset($_GET['step']))
	{
		$_step = $_GET['step'];
	}
	
	function checkEmptyPost($array)
	{
		foreach($array as $post_name)
		{
			if(!array_key_exists($post_name, $_POST))
				return false;
				
			if(empty($_POST[$post_name]))
				return false;	
		}
		
		return true;
	}
	
	/*
	 * NO TRAILING SLASH!
	 */
	function createDir($dir)
	{
		$old_umask = umask(0);
		
		$tc_dir = pathinfo($dir, PATHINFO_DIRNAME);

		if(!is_writable($tc_dir))
		{
			if(!@chmod($tc_dir, Yomm_Config::VAR_DIR_PERMISSION));
				return false;
		}
		mkdir($dir, Yomm_Config::VAR_DIR_PERMISSION);
		chmod($dir, Yomm_Config::VAR_DIR_PERMISSION);
		umask($old_umask);
		
		return true;
	}
	
	require 'tpl/header.php';
	
	require 'step_' . $_step . '.php';
	
	require 'tpl/footer.php';